//
// Description: 229. 求众数 II
// Created by Loading on 2021/10/22.
//

#include <bits/stdc++.h>

using namespace std;

vector<int> majorityElement(vector<int> &nums) {
    vector<int> res;
    unordered_map<int, int> m;
    int n = nums.size();

    for (auto &x : nums) {
        m[x]++;
    }
    for (auto &it : m) {
        if (it.second > n / 3) {
            res.emplace_back(it.first);
        }
    }

    return res;
}

int main() {
    vector<int> nums = {3, 2, 3};
    vector<int> res = majorityElement(nums);
    for (auto &x : res) {
        cout << x << ' ';
    }
    cout << endl;

    return 0;
}